﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using My.GenCode.Entities;
using My.GenCode.Interface;

namespace My.GenCode.Templates
{
    public class GenCreatePage : CodeTemplate
    {
        #region 覆盖父类的方法

        public GenCreatePage(string tpl, EntityInfo info,string desc) : base(tpl, info,desc) { }

        protected override string ProcTemplate()
        {
            _tpl = this.LoopProperties(_tpl, "<<CodeBlock>>", this.FormItemsCodeBlock); //处理<FormItemsCodeBlock>标签

            _tpl = _tpl.Replace("<FileName>", _nh.CreatePageFileName);                 // 处理<FileName>标签
            _tpl = _tpl.Replace("<<NameSpace>>", _nh.NameSpace);                       // 处理<NameSpace>标签
            _tpl = _tpl.Replace("<<EntityName>>", _nh.EntityName);                     // 处理<EntityName>标签
            _tpl = _tpl.Replace("<<CreateMethodName>>", _nh.CreateMethodName);         // 处理<CreateMethodName>标签

            return _tpl;
        }

        protected override string OutputFilename()
        {
            return @"Website\_Subpages\" + _nh.CreatePageFileName;
        }

        #endregion

        #region 私有方法,处理模板的循环标签

        private string FormItemsCodeBlock(string tpl,PropertyInfo info)
        {
            tpl = tpl.Replace("<Name>", info.Name);
            return tpl;
        }

        #endregion
    }
}